refactor(backend): extract admin CRUD into internal/admin package#16
Merged
refactor(backend): extract admin CRUD into internal/admin package#16
Conversation
Phase 2 of the directory restructure. The WebSocket layer is now
protocol-only; admin CRUD / config / import-export business logic
lives in a new transport-agnostic internal/admin package.
Changes:
- New internal/admin/ package with Operations struct. Files split by
feature: users.go, systems.go, talkgroups.go, tags.go, groups.go,
units.go, api_keys.go, dirmonitors.go, downstreams.go, webhooks.go,
shared_links.go, settings.go, transcription.go, radioreference.go,
filesystem.go, imports.go, exports.go. Does not import internal/ws
or net/http.
- internal/admin/operations.go defines the EventSink interface
(BroadcastAdminEvent, BroadcastCFG, DisconnectByUser, ClientCount).
ws.Hub implements it; Operations.New takes it at construction.
- internal/ws/admin_router.go replaces admin_ops.go as the transport
adapter. The adminOpHandlers map preserves every wire-protocol op
name (users.list, systems.create, config.update, export.config,
etc.) byte-identically. Live-state ops (activity.stats,
activity.chart, logs.query, logs.level, activity.top-talkgroups)
stay on *Client because they read hub in-memory state.
- internal/ws/admin_ops.go deleted (3,201 lines removed).
- Hub construction unchanged at the call site: NewHub(queries,
version, HubDeps{...}) still works. HubDeps is now a type alias
for admin.Deps.
- cmd/server/main.go updated: SensitiveSettingKeys moved from ws to
admin package.
- Tests: admin_ops_settings_test.go split into
internal/admin/settings_test.go (CRUD semantics) and
internal/ws/admin_router_test.go (dispatch + error envelope).
No wire-protocol, auth, or route changes. All frames, error
envelopes, and action names are byte-identical to before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The WebSocket layer is now protocol-only; admin CRUD, config, import, export, and radioreference business logic live in a new transport-agnostic
internal/adminpackage.internal/admin/package (62Operationsmethods across 18 files:users.go,systems.go,talkgroups.go,tags.go,groups.go,units.go,api_keys.go,dirmonitors.go,downstreams.go,webhooks.go,shared_links.go,settings.go,transcription.go,radioreference.go,filesystem.go,imports.go,exports.go,operations.go). No imports ofinternal/wsornet/http.internal/admin/operations.godefines anEventSinkinterface (BroadcastAdminEvent,BroadcastCFG,DisconnectByUser,ClientCount).ws.Hubimplements it;admin.Newtakes it at construction.internal/ws/admin_router.goreplacesadmin_ops.goas the thin transport adapter. TheadminOpHandlersmap preserves every wire op (users.list,systems.create,config.update,export.config, etc.) byte-identically.activity.stats,activity.chart,activity.top-talkgroups,logs.query,logs.level) stay on*Client— they read hub in-memory state that the admin package doesn't have.internal/ws/admin_ops.godeleted (3,201 lines).ws.HubDepsis now a type alias foradmin.Deps. Hub construction signature at the call site is unchanged:ws.NewHub(queries, version, ws.HubDeps{...})still works.main.goupdated:SensitiveSettingKeysmoved fromwstoadmin.Tests
admin_ops_settings_test.gowas split:internal/admin/settings_test.gointernal/ws/admin_router_test.go(new)Wire-protocol guarantee
Every
ADM_REQ/ADM_RESframe, action name, error envelope, and payload key is byte-identical to pre-PR. The frontend sees no change. There is an explicit test inadmin_router_test.gothat enumerates the expected wire ops and asserts the router exposes exactly that set (no additions, no missing).Blast radius
internal/adminis a net-new package with no external consumers outsideinternal/wsandcmd/serverDiff
Net +428 LOC (3,724 added, 3,296 removed — mostly a move out of the 3,201-line
admin_ops.go).Verification
go build ./... && go vet ./...— greengo test ./internal/ws/... ./internal/admin/... ./internal/api/...— all three packages passgo test ./...— full suite greenChangelog
[Unreleased]bullet added under### Changed.